package cz.muni.fi.xvano1.trinity.data;

import cz.muni.fi.xvano1.trinity.core.SecondaryParser;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.property.RRule;

/**
 * This class represents net.fortuna.ical4j.model.component.VEvent but in
 * simpler manner for easy output. Its methods are implemented as per JavaBeans
 * specification although this class is not JavaBean.
 *
 * @author Jan Vano
 */
public class Event {

    private String summary;
    private String startDateTime;
    private String endDateTime;
    private String recurrence;
    private String description;
    private String location;
    private String uid;

    /**
     * Constructor which takes net.fortuna.ical4j.model.component.VEvent and
     * copy values to instance of this class.
     * @param event 
     */
    public Event(VEvent event) {
        summary = event.getSummary().getValue();
        String[] start = SecondaryParser.parseDate(event.getStartDate().getDate().toString());
        String year = start[1];
        String month = start[2];
        String day = start[3];
        String startTime = start[4] + ":" + start[5];
        startDateTime = day + "." + month + "." + year + " " + startTime;
        String[] end = SecondaryParser.parseDate(event.getEndDate().getDate().toString());
        year = end[1];
        month = end[2];
        day = end[3];
        String endTime = end[4] + ":" + end[5];
        endDateTime = day + "." + month + "." + year + " " + endTime;
        /*end[3] + "." + end[2] + "." + end[1]
        + " " + endTime;*/
        try {
            recurrence = ((RRule) event.getProperty("RRULE")).getRecur().getFrequency();
        } catch (NullPointerException ex) {
            recurrence = "NONE";
        }
        description = event.getDescription().getValue();
        location = event.getLocation().getValue();
        uid = event.getUid().getValue();
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(String startDateTime) {
        this.startDateTime = startDateTime;
    }

    public String getEndDateTime() {
        return endDateTime;
    }

    public void setEndDateTime(String endDateTime) {
        this.endDateTime = endDateTime;
    }

    public String getRecurrency() {
        return recurrence;
    }

    public void setRecurrency(String recurrence) {
        this.recurrence = recurrence;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }
}
